//运用双指针的方法解决元素移除问题
public class Test {
    public static int removeElement(int[] nums, int val) {
        int k = 0;
        int j = 0;
        for(int i = 0;i < nums.length;i++) {
            if(nums[i] != val) {
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,6,2,25,6,8,2};
        int k = removeElement(nums,2);
        System.out.println(k);
        for (int i = 0; i < k; i++) {
            System.out.printf("%d ",nums[i]);;
        }
    }
}
